// Copyright 2008, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
#include <stdio.h>

#include "gtest/gtest.h"


class FooCalc {
public:
    FooCalc() {
    }
    int calc(int a, int b) {
        if (a == 0 || b == 0) {
            throw "dot't do that.";
        }
        int c = a % b;
        if (c == 0) 
            return b;
        return calc(b, c);
    }
    void init(){}
    void finalize(){}
};

// 全局事件
class FooEnvironment : public testing::Environment
{
public:
    virtual void SetUp()
    {
        std::cout << "Foo FooEnvironment SetUP" << std::endl;
    }
    virtual void TearDown()
    {
        std::cout << "Foo FooEnvironment TearDown" << std::endl;
    }
};

// testsuite事件。
class TestSuite : public testing::Test {
 protected:
    static void SetUpTestCase() {
        std::cout << "TestSuite SetUP." << std::endl;
    }
    static void TearDownTestCase() {
        std::cout << "TestSuite TearDown." << std::endl;
    }
};

TEST_F(TestSuite, Test1)
{
    // you can refer to shared_resource here 
}
TEST_F(TestSuite, Test2)
{
    // you can refer to shared_resource here 
}

// testcase事件。
class FooCalcTest:public testing::Test
{
protected:
    virtual void SetUp()
    {
        m_foo.init();
    }
    virtual void TearDown()
    {
        m_foo.finalize();
    }

    FooCalc m_foo;
};

TEST_F(FooCalcTest, HandleNoneZeroInput)
{
    EXPECT_EQ(4, m_foo.calc(12, 16));
}

TEST_F(FooCalcTest, HandleNoneZeroInput_Error)
{
    EXPECT_EQ(4, m_foo.calc(12, 16));
}


int main(int argc, char** argv) {
    //  添加全局事件。
    testing::AddGlobalTestEnvironment(new FooEnvironment);
    testing::InitGoogleTest(&argc, argv);
    return RUN_ALL_TESTS();
}
